package com.sti.framework.models.Aps.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sti.framework.core.web.Page;
import com.sti.framework.models.Aps.data.ApsMonthPlanMo;
import com.sti.framework.models.Aps.data.ApsMonthPlanMoGroup;
import com.sti.framework.models.Aps.data.ApsMonthPlanMoResult;
import com.sti.framework.models.Basics.data.BasicsParameter;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface ApsMonthPlanMoResultMapper extends BaseMapper<ApsMonthPlanMoResult> {

    /**
     * 铸造计划列表
     */
    @Select("SELECT class_type classType,schedule_date scheduleDate,sum(schedule_cnt) scheduleCnt,SUM(weight) weightAll,SUM(weight_out) weightOutAll,sum(weight_in) weightInAll," +
            "sum(weight * cast_cnt) castWeight, case when class_type = 1 then '铸造乙班' when class_type = 2 then '铸造甲班' end classTypeGroup, " +
            "case when class_type = 1 then '白班' when class_type = 2 then '夜班' end classTypeStr FROM aps_month_plan_mo_result ${ew.customSqlSegment} " +
            "GROUP BY schedule_date,class_type ORDER BY schedule_date desc,class_type asc")
    IPage<ApsMonthPlanMoGroup> getByClassGroupList(Page page, @Param("ew") LambdaQueryWrapper<ApsMonthPlanMoResult> queryWrapper);

    /**
     * 根据日期和班次铸造计划
     */
    @Select("SELECT class_type classType,schedule_date scheduleDate,sum(schedule_cnt) scheduleCnt,SUM(weight) weightAll,SUM(weight_out) weightOutAll,sum(weight_in) weightInAll," +
            "sum(weight * cast_cnt) castWeight, case when class_type = 1 then '铸造乙班' when class_type = 2 then '铸造甲班' end classTypeGroup, " +
            "case when class_type = 1 then '白班' when class_type = 2 then '夜班' end classTypeStr FROM aps_month_plan_mo_result ${ew.customSqlSegment} " +
            "GROUP BY schedule_date,class_type ORDER BY schedule_date desc,class_type asc")
    ApsMonthPlanMoGroup getByClassGroupListOne(@Param("ew") LambdaQueryWrapper<ApsMonthPlanMoResult> queryWrapper);
}
